package leetcode;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 描述:104. 二叉树的最大深度
 *
 * @author Madison You
 * @created 22:14
 */
public class Easy_104_MaxDepth {

    public static void main(String[] args) {

    }

    Queue<TreeNode> queue = new LinkedBlockingQueue<>();

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int deep = 1;
        queue.offer(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            deep++;
            for (int i = 0; i < size; i++) {
                TreeNode poll = queue.poll();
                if (poll.left != null) {
                    queue.offer(poll.left);
                }
                if (poll.right != null) {
                    queue.offer(poll.right);
                }
            }
        }
        return deep;
    }

}
